import axios from 'axios'
//定位城市函数
export const getCurrentCity = () => {
  //获取localStorage中的hkzf_city进行对象封装
  const localCity = JSON.parse(localStorage.getItem('hkzf_city'))
  //如果地址不存在
  if (!localCity) {
    return new Promise((resolve, reject) => {
      const curCity = new window.BMapGL.LocalCity()
      //获取当地城市
      curCity.get(async (res) => {
        try {
          const result = await axios.get('http://localhost:8080/area/info?', {
            params: {
              name: res.name,
            },
          })
          //存储localStorage中的hkzf_city进行字符串封装
          localStorage.setItem('hkzf_city', JSON.stringify(result.data.body))
          resolve(result.data.body)
        } catch (error) {
          reject(error)
        }
      })
    })
  }
  //如果地址存在
  return Promise.resolve(localCity)
}

export { API } from './api'
export { BASE_URL } from './url'
export * from './auth'
export * from './city'
